package com.example.myapplication

import android.os.Bundle
import android.view.ViewGroup
import androidx.activity.ComponentActivity
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Button
import android.widget.ImageView


class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL

        val imageView = ImageView(this)
        imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        imageView.setImageResource(R.drawable.flag)
        linearLayout.addView(imageView)

        val textView = TextView(this)

        textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        //文字居中
        textView.gravity = 1
        textView.textSize = 30F
        textView.text = getString(R.string.textView)
        linearLayout.addView(textView)

        val button = Button(this)
        button.width = ViewGroup.LayoutParams.WRAP_CONTENT
        button.height = ViewGroup.LayoutParams.WRAP_CONTENT
        button.text = getString(R.string.button)
        button.setOnClickListener {
            textView.text = getString(R.string.clicked)
        }
        linearLayout.addView(button)

        setContentView(linearLayout)

    }
}

